package com.account.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
public class AccountController {

    final static Map<Integer, User> userMap = new HashMap() {
        {
            put(1, new User(1, "张三"));
            put(2, new User(2, "李四"));
            put(3, new User(3, "赵云"));
        }
    };

    @Autowired
    private BalanceService balanceService;

    @RequestMapping("/acc/user")
    public User getBalance(@RequestParam Integer id){
        System.out.println("request:/acc/user?id="+id);
        if(id!=null && userMap.containsKey(id)){
            User user =userMap.get(id);
            user.setBalance(balanceService.getBalance(id));
            return user;
        }
        return new User(0,"");
    }

}
